# Example Python script to read model in hdf5 formatted file

# Model types:
# 00: Main Field Model
# 01: Main Field + Zonal Flux Velocity Model

# Model type 00 and 01:
# array g contains the magnetic field coefficients in the standard ordering 

# Model type 01:
# array v contains the zonal flux velocity coefficents (t1, t2, t3, ...)

# All coefficients are for Schmidt normalized associated Legendre polynomials.

import numpy as np
import h5py

INPUT_MODEL = '<model path>' + '.hdf5'

with h5py.File(INPUT_MODEL, 'r') as hm:
        model_type = hm.attrs['model_type']
        itype = int(model_type[:2])
        B_dset = hm['B_field_coeffs']
        lmax = B_dset.attrs['lmax']
        g = np.array(B_dset)
        if itype == 1 :
            v_dset = hm['zfv_coeffs']
            v = np.array(v_dset)
            lmaxv = v_dset.attrs['lmax']

print(f"lmax for magnetic field: {lmax:}")
if itype !=0 :
    print(f"lmax for zonal velocity field: {lmaxv:}")